#include <iostream>

using namespace std;

class Girl;
class Partner {
public:
	Girl* girl;
	Partner(Girl& girl);
	void visit();
};
// 当使用成员函数 做友元的时候 Girl 里面 用到了 Partner的方法，所以 
// Partner 的 visit()声明一定要在 Girl的前面 否则会报错
class Girl {
	//friend class Partner;
	friend void Partner::visit();
	friend void test(Partner& p);
public:
	string name;
	Girl(string name, int age);
private:
	int age;
};

// 类的定义
Girl::Girl(string name, int age) :name(name), age(age) {}
Partner::Partner(Girl& girl) {
	this->girl = &girl;
}
void Partner::visit() {
	cout << "my partner`s age is " << this->girl->age << endl;
}

void test(Partner& p) {
	cout << "test(): girl`s age is " << p.girl->age;
}
int main() {
	Girl girl("tx", 18);
	Partner pa(girl);
	pa.visit();

	test(pa);

	return 0;
}